<template>
  <lb-layout
    v-loading="$store.getters.loading"
    element-loading-text="拼命加载中"
    element-loading-spinner="el-icon-loading"
    element-loading-background="#a19f9fb0;"
    :paddBottom="5"
  >
    <aps-form
      :config="apsForm.formConfig"
      :model="apsForm.formData"
      :formRef="apsForm.formRef"
      :labelWidth="apsForm.labelWidth"
      ref="form"
    ></aps-form>
    <lb-table
      :column="tableData.column"
      :data="tableData.data"
      border
      :height="700"
      pagination
      background
      layout="total, sizes, prev, pager, next, jumper"
      :page-sizes="[20, 40, 60, 80]"
      :pager-count="5"
      :current-page.sync="currentPage"
      :total="total"
      :page-size="pageSize"
      @size-change="handleSizeChange"
      @p-current-change="handleCurrentChange"
    >
    </lb-table>
    <component
      :is="modelName"
      :id="id"
      :visible.sync="show"
      @close="close"
    ></component>
  </lb-layout>
</template>

<script>
import {} from "@/api/park/parkmsg.js";

import operate from "@/views/resource/energyType/components/operate.vue";
export default {
  name: "",
  components: {
    operate,
  },
  dicts: [],
  data() {
    return {
      //弹窗
      id: "",
      modelName: "",
      show: false,
      apsForm: {
        formRef: "form",
        labelWidth: "auto",
        formData: {},
        formConfig: {
          formAttr: {
            inline: true,
            size: "small",
          },
          properties: {
            subentryType: {
              label: "类型名称",
              typeName: "el-input",
              placeholder: "请输入类型名称",
            },
          },
          formSoltButton: [
            {
              label: "搜索",
              type: "primary",
              typeName: "el-button",
              size: "small",
              icon: "el-icon-search",
              click: this.handlerSearchDetail,
            },
            {
              label: "重置",
              typeName: "el-button",
              size: "small",
              icon: "el-icon-refresh-left",
              click: this.handleReset,
            },
            {
              label: "新增",
              type: "primary",
              typeName: "el-button",
              plain: true,
              size: "small",
              icon: "el-icon-plus",
              click: () => this.showModel("operate"),
            },
          ],
        },
      },
      currentPage: 1,
      pageSize: 20,
      total: 0,
      tableData: {
        column: [
          {
            prop: "",
            label: "类型名称",
            minWidth: 100,
            align: "center",
            showOverflowTooltip: true,
          },
          {
            prop: "",
            label: "备注",
            minWidth: 100,
            align: "center",
            showOverflowTooltip: true,
          },
          {
            label: "操作",
            width: "120",
            fixed: "right",
            render: (h, scope) => {
              let that = this;
              let a, b;
              a = (
                <el-button
                  type="text"
                  size="small"
                  icon="el-icon-edit"
                  onClick={() => {}}
                >
                  编辑
                </el-button>
              );
              b = (
                <el-button
                  type="text"
                  size="small"
                  icon="el-icon-delete"
                  onClick={() => {
                    that.handlerDelete(scope.row);
                  }}
                  class="text-danger"
                >
                  删除
                </el-button>
              );
              return (
                <div>
                  {a}
                  {b}
                </div>
              );
            },
          },
        ],
        data: [],
      },
    };
  },
  created() {},
  mounted() {},
  methods: {
    async initData(data) {
      let that = this;
      let query = {
        ...data,
      };
      query.pageNum = that.currentPage;
      query.pageSize = that.pageSize;
      // that.$store.commit("app/updateApiCount", "add");
      // await requestWay(query)
      //   .then((res) => {
      //     that.$store.commit("app/updateApiCount");
      //     if (res.code === 700) {
      //       this.$message.warning(res.msg);
      //       return false;
      //     }
      //     that.tableData.data = res?.rows ?? [];
      //     that.total = res?.total ?? 0;
      //   })
      //   .catch((err) => {
      //     that.$store.commit("app/updateApiCount");
      //     this.$message.error("系统错误,请联系管理员!");
      //   });
    },
    // 搜索
    handlerSearchDetail() {
      const { ...other } = this.$refs?.form?.getFieldsValue();
      const data = {
        ...other,
      };
      this.initData(data);
    },
    // 重置
    handleReset() {},
    handleSizeChange(val) {
      this.currentPage = 1;
      this.pageSize = val;
      this.handlerSearchDetail();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.handlerSearchDetail();
    },
    // 删除
    handlerDelete(row) {
      let that = this;
      let id = row.id;
      const text = "是否确认删除" + (row?.name ?? "该条数据") + "？";
      this.$modal
        .confirm(text)
        .then(() => {
          that.delectRequest(id);
        })
        .catch(() => {
          that.$message({
            message: "取消删除",
          });
        });
    },
    // 删除请求
    delectRequest(id) {},
    // 弹窗
    showModel(name, params) {
      this.modelName = name;
      this.id = params?.id || "";
      setTimeout(() => {
        this.show = true;
      }, 200);
    },
    close(status) {
      this.show = false;
      setTimeout(() => {
        if (status) this.handlerSearchDetail();
      }, 200);
    },
  },
};
</script>

<style lang="scss" scoped></style>
